<%@ page import="com.google.appengine.api.utils.SystemProperty; grails.util.Environment; org.codehaus.groovy.grails.commons.GrailsApplication; org.codehaus.groovy.grails.web.context.GrailsConfigUtils; com.google.appengine.api.users.UserServiceFactory; com.google.appengine.api.users.UserService; dk.fuddi.grails.Earthquake" %>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  <meta name="layout" content="main"/>
  <title>Edit Earthquake</title>
</head>
<body>
<div class="nav">
  <span class="menuButton"><a class="home" href="${resource(dir: '')}">Home</a></span>
  <span class="menuButton"><g:link class="list" action="list">Earthquake List</g:link></span>
  <span class="menuButton"><g:link class="create" action="create">New Earthquake</g:link></span>
</div>
<div class="body">
  <h1>Edit Earthquake</h1>
  <g:if test="${flash.message}">
    <div class="message">${flash.message}</div>
  </g:if>
  <g:hasErrors bean="${earthquakeInstance}">
    <div class="errors">
      <g:renderErrors bean="${earthquakeInstance}" as="list"/>
    </div>
  </g:hasErrors>

  <%
    UserService userService = UserServiceFactory.getUserService();
    if (!userService.isUserLoggedIn() && !SystemProperty.environment == SystemProperty.Environment.Value.Development) {
  %>
    Please <a href="<%= userService.createLoginURL("/newLogin.jsp") %>">log in</a>
   <% } else { %>

  <g:form method="post">
    <input type="hidden" name="id" value="${earthquakeInstance?.id}"/>
    <input type="hidden" name="version" value="${earthquakeInstance?.version}"/>
    <div class="dialog">
      <table>
        <tbody>

        <tr class="prop">
          <td valign="top" class="name">
            <label for="lat">Lat:</label>
          </td>
          <td valign="top" class="value ${hasErrors(bean: earthquakeInstance, field: 'lat', 'errors')}">
            <g:textField name="lat" value="${earthquakeInstance.lat}"/>
          </td>
        </tr>

        <tr class="prop">
          <td valign="top" class="name">
            <label for="lng">Lng:</label>
          </td>
          <td valign="top" class="value ${hasErrors(bean: earthquakeInstance, field: 'lng', 'errors')}">
            <g:textField name="lng" value="${earthquakeInstance.lng}"/>
          </td>
        </tr>

        <tr class="prop">
          <td valign="top" class="name">
            <label for="magnitude">Magnitude:</label>
          </td>
          <td valign="top" class="value ${hasErrors(bean: earthquakeInstance, field: 'magnitude', 'errors')}">
            <g:textField name="magnitude" value="${earthquakeInstance.magnitude}"/>
          </td>
        </tr>

        <tr class="prop">
          <td valign="top" class="name">
            <label for="name">Name:</label>
          </td>
          <td valign="top" class="value ${hasErrors(bean: earthquakeInstance, field: 'name', 'errors')}">
            <g:textField name="name" value="${earthquakeInstance?.name}"/>
          </td>
        </tr>

        <tr class="prop">
          <td valign="top" class="name">
            <label for="title">Title:</label>
          </td>
          <td valign="top" class="value ${hasErrors(bean: earthquakeInstance, field: 'title', 'errors')}">
            <g:textField name="title" value="${earthquakeInstance?.title}"/>
          </td>
        </tr>

        <tr class="prop">
          <td valign="top" class="name">
            <label for="updated">Updated:</label>
          </td>
          <td valign="top" class="value ${hasErrors(bean: earthquakeInstance, field: 'updated', 'errors')}">
            <g:textField name="updated" value="${earthquakeInstance?.updated}"/>
          </td>
        </tr>

        </tbody>
      </table>
    </div>
    <div class="buttons">
      <span class="button"><g:actionSubmit class="save" value="Update"/></span>
      <span class="button"><g:actionSubmit class="delete" onclick="return confirm('Are you sure?');" value="Delete"/></span>
    </div>
  </g:form>

  <% } %>
</div>
</body>
</html>
